{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Python 元组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 2, 4, 3, 6, 'adb', 'python')\n",
      "90\n"
     ]
    },
    {
     "ename": "NameError",
     "evalue": "name 'tup2' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-8-379b6b5c660d>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     17\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     18\u001b[0m \u001b[1;32mdel\u001b[0m \u001b[0mtup2\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 19\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtup2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'tup2' is not defined"
     ]
    }
   ],
   "source": [
    "'''\n",
    "python的元组与列表类似，不同之处在于元组的元素不能修改。\n",
    "\n",
    "元组使用小括号，列表使用方括号。\n",
    "\n",
    "元组创建很简单，只需要在括号中添加元素，并使用逗号隔开即可。\n",
    "\n",
    "'''\n",
    "\n",
    "\n",
    "tup1 = (1,2,4,3,6,\"adb\",'python')\n",
    "\n",
    "tup2 = (90,)# 元组中只包含一个元素时，需要在元素后面添加逗号\n",
    "\n",
    "print(tup1)\n",
    "print(tup2[0])\n",
    "\n",
    "del tup2\n",
    "# print(tup2)# 元组被删除后，输出变量会有异常信息， name 'tup2' is not defined"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
